package com.stx.boke.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.stx.boke.dao.UserDao;
import com.stx.boke.dao.impl.UserDaoImpl;
import com.stx.boke.entity.Blogger;

/**
 * Servlet implementation class BlogQuery
 */
public class BlogQuery extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	
	UserDao dao=null;
	@Override
	public void init() throws ServletException {
		// 初始化Dao对象
		dao = new UserDaoImpl();
	}
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BlogQuery() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Blogger bloggerparams=new Blogger();
		
		try {
			// 调用dao中查询
			List<Blogger> bloList = dao.getBlogger(bloggerparams);

			// 将查询结果保存到request对象中
			request.setAttribute("bloList", bloList);

			// 通过ServletContext对象获取RequestDispatcher对象
			// 通过ServletContext对象获得的路径是 相对Web应用根的路径,即绝对路径.
			RequestDispatcher rd = getServletContext().getRequestDispatcher("/jsp/取出博客信息.jsp");

			// 请求转发给学生信息列表页面(/jsp/student/studentList.jsp)
			rd.forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
			}
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}

}
